package com.chb.friend2;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class SortReducer extends Reducer<User, User, Text, Text>{
	@Override
	protected void reduce(User key, Iterable<User> values, Context context) 
			throws IOException,
			InterruptedException { 
		//由于自定义了分组，和排序，所以进入reudce中的数据按照组进行处理，每组是按照fofNum降序排序
		String user = key.getUserName();
		StringBuilder sb = new StringBuilder();
		for (User u : values) {
			//提取fof好友，和fofNum
			sb.append(u.getUserName()+":"+u.getFofNum()+";");
		}
		context.write(new Text(user), new Text(sb.toString()));
	}
}
